package com.mzj.saas.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.pojo.ContractTemplate;
import com.haixiaoke.saas.repository.service.IContractTemplateService;
import com.mzj.saas.annotation.CheckAuth;
import com.mzj.saas.commons.pdf.HtmlToPdfUtils;
import com.mzj.saas.util.LoginUserUtil;
import org.apache.http.util.TextUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 合同模板管理Controller
 *
 * @author zhiping
 * @date 2023-04-13
 */
@RestController
@RequestMapping("/contract/contractTemplate")
public class ContractTemplateController extends BaseController {
    @Autowired
    private IContractTemplateService contractTemplateService;
    @Autowired
    private LoginUserUtil loginUserUtil;


    /**
     * 查询合同模板管理列表
     */
    @CheckAuth
    @GetMapping("/list")
    public AjaxResult list(ContractTemplate contractTemplate) {
        Long orgId = loginUserUtil.getOrgId();
        contractTemplate.setOrgId(orgId);
        return success(contractTemplateService.selectContractTemplateList(contractTemplate));
    }

    /**
     * 获取合同模板管理详细信息
     */
    @CheckAuth
    @GetMapping(value = "/{templateId}")
    public AjaxResult getInfo(@PathVariable("templateId") Long templateId) {
        return success(contractTemplateService.selectContractTemplateByTemplateId(templateId));
    }

    /**
     * 新增合同模板管理
     */
    @CheckAuth
    @PostMapping
    public AjaxResult add(@RequestBody ContractTemplate contractTemplate) {
        Long orgId = loginUserUtil.getOrgId();
        contractTemplate.setOrgId(orgId);
        return toAjax(contractTemplateService.insertContractTemplate(contractTemplate));
    }

    /**
     * 修改合同模板管理
     */
    @PutMapping
    @CheckAuth
    public AjaxResult edit(@RequestBody ContractTemplate contractTemplate) {
        return toAjax(contractTemplateService.updateContractTemplate(contractTemplate));
    }

    /**
     * 删除合同模板管理
     */
    @CheckAuth
    @DeleteMapping("/{templateIds}")
    public AjaxResult remove(@PathVariable Long[] templateIds) {
        return toAjax(contractTemplateService.deleteContractTemplateByTemplateIds(templateIds));
    }


    /**
     * 启用模板
     *
     * @param templateId
     * @return
     */
    @CheckAuth
    @PutMapping("/enable/{templateId}")
    public AjaxResult enable(@PathVariable Long templateId) {
        Long orgId = loginUserUtil.getOrgId();
        return toAjax(contractTemplateService.enableTemplate(orgId, templateId));
    }

    /**
     * 禁用模板
     *
     * @param templateId
     * @return
     */
    @CheckAuth
    @PutMapping("/disable/{templateId}")
    public AjaxResult disable(@PathVariable Long templateId) {
        Long orgId = loginUserUtil.getOrgId();
        return toAjax(contractTemplateService.disableTemplate(orgId, templateId));
    }

}
